/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 */

#ifndef MAINFRAME_H
#define MAINFRAME_H
/*主框架头文件*/
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checklst.h>
#include <wx/listbox.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/arrstr.h>
#include <vector>

#include <tinyxml.h>

class MainFrame : public wxFrame {
public:
    MainFrame(wxWindow *parent, wxWindowID id = -1);

    virtual ~MainFrame();

    static const long ID_LBL_STEPS;
    static const long ID_LBL_FILE_SRC;
    static const long ID_LBL_FILE_DST;
    static const long ID_TXT_FILE_SRC;
    static const long ID_BTN_FILE_SRC;
    static const long ID_TXT_FILE_DST;
    static const long ID_BTN_FILE_DST;
    static const long ID_CFG_SRC;
    static const long ID_LST_CFG;
    static const long ID_BTN_TRANSFER;
    static const long ID_BTN_UNCHECK;
    static const long ID_BTN_EXPORT_ALL;
    static const long ID_BTN_EXPORT;
    static const long ID_BTN_SAVE;
    static const long ID_BTN_CLOSE;
protected:
    void OnBtnFileSrcClick(wxCommandEvent &event);
    void OnBtnFileDstClick(wxCommandEvent &event);
    void OnBtnTransferClick(wxCommandEvent &event);
    void OnBtnUncheckClick(wxCommandEvent &event);
    void OnBtnExportAllClick(wxCommandEvent &event);
    void OnBtnExportClick(wxCommandEvent &event);
    void OnBtnSaveClick(wxCommandEvent &event);
    void OnBtnCloseClick(wxCommandEvent &event);

    wxBoxSizer *bszSteps;
    wxGridSizer *grsAction;
    wxTextCtrl *txtFileDst;
    wxStaticBoxSizer *sbsSteps;
    wxBoxSizer *bszMain;
    wxStaticText *lblFileSrc;
    wxCheckListBox *clbCfgSrc;
    wxButton *btnFileSrc;
    wxFlexGridSizer *flsFileDst;
    wxFlexGridSizer *flsFileSrc;
    wxTextCtrl *txtFileSrc;
    wxGridSizer *grsFile;
    wxGridSizer *grsCfg;
    wxButton *btnFileDst;
    wxListBox *lstCfgDst;
    wxStaticText *lblFileDst;
    wxGridSizer *grsFileLabel;
    wxStaticText *lblSteps;
private:
    /*文件选择器*/
    wxString FileSelector();
    /*载入配置*/
    bool LoadConfig(const wxString &filename, TiXmlDocument **doc);
    /*检测是否在统一文件*/
    bool SameConfig(const wxString &filename, wxTextCtrl *txt);
    /*将配置放入wxCheckListBox或wxllistbox*/
    void OfferConfig(TiXmlDocument *config, wxListBox *listbox, std::vector<TiXmlNode *> *nodes);
    /*将配置节点选项添加到节点上*/
    void OfferNode(TiXmlNode **node, wxListBox *listbox, std::vector<TiXmlNode *> *nodes, const wxString &prefix = wxT(""));
    /*移动配置选项节点*/
    bool TransferNode(TiXmlNode **node, const wxArrayString &path);
    /*附加上配置选项节点*/
    void AttachNode(size_t idx, TiXmlElement *root);
    /*目录数组*/
    wxArrayString PathToArray(const wxString &path);
    /*以下加载/保存TinyXML文档的方法是从C::B中获取和修改的.在那里所做的更改可能也必须在这里应用.修改:删除对C::B SDK(C::B管理器类)的依赖.*/
    bool TiXmlLoadDocument(const wxString &filename, TiXmlDocument *doc);
    bool TiXmlSaveDocument(const wxString &filename, TiXmlDocument *doc);
    bool TiXmlSuccess(TiXmlDocument *doc);
    wxString mFileSrc;
    TiXmlDocument *mCfgSrc;
    bool mCfgSrcValid;
    std::vector<TiXmlNode *> mNodesSrc;

    wxString mFileDst;
    TiXmlDocument *mCfgDst;
    bool mCfgDstValid;
    std::vector<TiXmlNode *> mNodesDst;

DECLARE_EVENT_TABLE()
};

#endif
